package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.common.TokenException;
import com.itheima.service.RefreshTokenService;
import com.itheima.vo.TokenVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <h1>刷新token控制类</h1>
 *
 * @author <a href="11n_yd2h5e1jx8@dingtalk.com">叶世铭</a>
 * @since 2023/2/2
 */
@RestController
@RequestMapping("/refresh")
@Api(tags = "刷新token")
public class RefreshTokenController {

    @Resource
    private RefreshTokenService refreshTokenService;

    /**
     * 刷新Token
     *
     * @param request 请求参数
     * @return 刷新tokenVo
     * @throws TokenException
     */
    @PutMapping
    @ApiOperation(value = "刷新token")
    public R<TokenVo> refreshToken(HttpServletRequest request) throws TokenException {
        return R.success(refreshTokenService.refreshToken(request));
    }
}
